/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using DaveSexton.DocProject.Sandcastle.TopicManagement;

namespace DaveSexton.DocProject.Sandcastle.ContentManagement
{
	[Serializable]
	public class ContentItemAttributeData		// Attribute is a reserved suffix, so Data was appended
	{
		#region Public Properties
		public string Name
		{
			get
			{
				return name;
			}
			set
			{
				if (nameReadOnly)
					throw new InvalidOperationException(string.Format(System.Globalization.CultureInfo.CurrentCulture,
						Resources.Errors.ReadOnlyProperty, "Name"));

				name = value;
			}
		}

		public virtual TopicSectionAttributeType AttributeType
		{
			get
			{
				return TopicSectionAttributeType.String;
			}
		}

		public virtual string Value
		{
			get
			{
				return _value;
			}
			set
			{
				if (!string.Equals(value, _value ?? "", StringComparison.Ordinal))
				{
					_value = value;
					owner.NotifyAttributeChanged(this);
				}
			}
		}

		public ContentItem Owner
		{
			get
			{
				return owner;
			}
		}
		#endregion

		#region Private / Protected
		private string name, _value;
		private readonly ContentItem owner;
		private readonly bool nameReadOnly;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="ContentItemAttributeData" /> class for derived classes.
		/// </summary>
		protected ContentItemAttributeData(ContentItem owner)
		{
			if (owner == null)
				throw new ArgumentNullException("owner");

			this.owner = owner;
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="ContentItemAttributeData" /> class.
		/// </summary>
		public ContentItemAttributeData(ContentItem owner, string name)
			: this(owner)
		{
			if (string.IsNullOrEmpty(name))
				throw new ArgumentException(Resources.Errors.NullOrEmpty, "name");

			this.name = name;
			nameReadOnly = true;
		}
		#endregion
	}
}
